package easy.最后一个单词的长度;

/**
 * 最后一个单词的长度
 *
 * @author CodeX
 * @since 2021-09-28 14:59:29
 */
public class LengthOfLastWord {
    public static int lengthOfLastWord(String s) {
        s = s.trim();
        int index = s.lastIndexOf(" ");
        s = s.substring(index + 1);
        return s.length();
    }

    public static void main(String[] args) {
        String s = "    fly me to the moon        ";
        System.out.println(lengthOfLastWord(s));
    }
}
